import { FormSchema } from '/@/components/Form';
import { BasicColumn } from '/@/components/Table';
import dayjs from 'dayjs';
import { useUserStore } from '/@/store/modules/user';
const userStore = useUserStore();

//列表数据
export const columns: BasicColumn[] = [
  {
    title: 'id',
    dataIndex: 'id',
    width: 100,
    ifShow: false,
  },
  // {
  //   title: '考核周期',
  //   dataIndex: 'periodCode',
  //   width: 100,
  //   align: 'center',
  // },
  {
    title: '工作时间',
    dataIndex: 'endDate',
    width: 120,
    align: 'center',
  },
  {
    title: '所在班组',
    dataIndex: 'orgName',
    width: 150,
    align: 'center',
  },
  {
    title: '员工姓名',
    dataIndex: 'psnName',
    width: 260,
    align: 'center',
  },
  {
    title: '工作项类型',
    dataIndex: 'workTypeName',
    width: 150,
    align: 'center',
  },
  {
    title: '工作项名称',
    dataIndex: 'workName',
    width: 150,
    align: 'center',
  },
  {
    title: '工作说明',
    dataIndex: 'workExplReg',
    width: 150,
    align: 'center',
    ellipsis: true,
    customRender: ({ text }) => {
      try {
        //去掉后端返回的null和null字符串
        text = text || '';
        text = text.replace('null,', '');
        text = text.replace('null', '');
      } catch (e) {
        console.log(e);
      }
      return text;
    },
  },
  {
    title: '数据来源',
    dataIndex: 'addMode',
    width: 150,
    align: 'center',
    customRender: ({ text }) => {
      let textDesc:any = null;
      if (text == '10') {
        textDesc = '按任务登记';
      } else if (text == '20') {
        textDesc = '按人员登记';
      } else if (text == '30') {
        textDesc = '二维表登记';
      } else if (text == '30') {
        textDesc = '安管系统导入';
      } else if (text == '40') {
        textDesc = '数据中台';
      } else if (text == '41') {
        textDesc = '数字化供电所全业务平台';
      }
      // try {
      //   //去掉后端返回的null和null字符串
      //   text = text || '';
      //   text = text.replace('null,', '');
      //   text = text.replace('null', '');
      // } catch (e) {
      //   console.log(e);
      // }
      return textDesc ? textDesc : '';
    },
  },
];

//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    field: 'periodCode',
    label: '考核周期',
    component: 'Select',
    colProps: { span: 6 },
    defaultValue: dayjs().format('YYYYMM'),
  },
  {
    field: 'orgCode',
    component: 'Select',
    label: '班组1',
    componentProps: {
      options: userStore.getTeamList,
    },
    defaultValue: userStore.getOrgCode,
    colProps: { span: 6, },
  },
  {
    field: 'happenDate',
    label: '工作时间',
    component: 'RangePicker',
    componentProps: {
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
    },
    colProps: { span: 8 },
  },
  {
    field: 'psnName',
    label: '员工姓名',
    component: 'Input',
    colProps: { span: 6 },
  },
];

//按任务登记 数量积分 数量+质量积分 表单固定部分
export const taskForm: FormSchema[] = [
  {
    field: 'workItemName',
    label: '工作项',
    component: 'Input',
    dynamicDisabled: () => true,
    colProps: { span: 8 },
  },
  {
    field: 'workItemCode',
    label: '工作项目编码',
    component: 'Input',
    show: false,
  },
  {
    field: 'endDate',
    label: '工作时间',
    component: 'DatePicker',
    componentProps: {
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
    },
    defaultValue: dayjs(),
    required: true,
    colProps: { span: 8 },
  },
  {
    field: 'standardValue',
    label: '标准分值',
    component: 'Input',
    colProps: { span: 8 },
    dynamicDisabled: () => true,
  },
  {
    field: 'workQualityCriterion',
    label: '工作质量标准',
    component: 'InputTextArea',
    dynamicDisabled: () => true,
    show: true,
    colProps: { span: 32 },
  },
];

//按任务登记 数量积分 数量+质量积分 表格表头固定部分
export const taskColumns: BasicColumn[] = [
  {
    title: 'id',
    dataIndex: 'id',
    ifShow: false,
    width: 90,
  },
  {
    title: '员工姓名',
    dataIndex: 'psnName',
    width: 65,
  },
  {
    title: '员工工号',
    dataIndex: 'psnNum',
    ifShow: false,
  },
  {
    title: '班组编码',
    dataIndex: 'orgCode',
    ifShow: false,
  },
  {
    title: '班组名称',
    dataIndex: 'orgName',
    ifShow: false,
  },
  {
    title: '标准分值',
    dataIndex: 'stdscore',
    width: 60,
    ifShow: false,
  },
  {
    title: '次数',
    dataIndex: 'unit',
    width: 60,
    editRow: true,
    editComponent: 'InputNumber',
  },
  {
    title: '工作量得分',
    dataIndex: 'workPoints',
    width: 90,
  },
  {
    title: '质量得分',
    dataIndex: 'qspoints',
    editRow: true,
    width: 90,
    editComponent: 'InputNumber',
  },
  {
    title: '积分',
    dataIndex: 'sumPoints',
    width: 80,
    fixed: 'right',
    sorter: true,
  },
  {
    title: '工作说明',
    dataIndex: 'workExpl',
    fixed: 'right',
    editRow: true,
    width: 90,
  },
];

//按人员登记表单
export const pepForm: FormSchema[] = [
  {
    label: '班员工号',
    field: 'psnNum',
    component: 'Input',
    show: false,
  },
  {
    label: '班员',
    field: 'psnName',
    component: 'Input',
    dynamicDisabled: () => true,
    colProps: { span: 12 },
  },
  {
    field: 'endDate',
    label: '发生日期',
    component: 'DatePicker',
    componentProps: {
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
    },
    defaultValue: dayjs(),
    required: true,
    colProps: { span: 12 },
  },
];

//按人员等级表格固定表头
export const pepColumns: BasicColumn[] = [
  {
    title: 'id',
    dataIndex: 'id',
    ifShow: false,
    width: 90,
  },
  {
    title: '员工姓名',
    dataIndex: 'orgName',
    ifShow: false,
  },
  {
    title: '员工工号',
    dataIndex: 'orgCode',
    ifShow: false,
  },
  {
    title: '班组编码',
    dataIndex: 'orgCode',
    ifShow: false,
  },
  {
    title: '班组名称',
    dataIndex: 'orgName',
    ifShow: false,
  },
  {
    title: '工作任务',
    dataIndex: 'rationName',
    width: 90,
  },
  {
    title: '标准分值',
    dataIndex: 'stdscore',
    width: 60,
  },
  {
    title: '次数',
    dataIndex: 'unit',
    width: 60,
    editRow: true,
    editComponent: 'InputNumber',
  },
  {
    title: '工作量得分',
    dataIndex: 'workPoints',
    width: 90,
  },
  {
    title: '质量得分',
    dataIndex: 'qspoints',
    editRow: true,
    width: 90,
    editComponent: 'InputNumber',
  },
  {
    title: '积分',
    dataIndex: 'sumPoints',
    width: 80,
    fixed: 'right',
  },
  {
    title: '工作说明',
    dataIndex: 'workExpl',
    fixed: 'right',
    editRow: true,
    width: 90,
  },
];

// 按二维表

export const twoForm: FormSchema[] = [
  {
    field: 'endDate',
    label: '工作时间',
    component: 'DatePicker',
    componentProps: {
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
    },
    defaultValue: dayjs(),
    required: true,
    colProps: { span: 12 },
  },
];

export const twoColumns: BasicColumn[] = [
  {
    title: 'id',
    dataIndex: 'id',
    ifShow: false,
    width: 90,
  },
  {
    title: '员工姓名',
    dataIndex: 'psnName',
    width: 150,
  },
  {
    title: '总分',
    dataIndex: 'sumPoints',
    width: 150,
  },
];

// 安管系统导入
export const systemForm: FormSchema[] = [
  {
    field: 'rationName',
    label: '工程名称',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'fzr',
    label: '负责人',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'psnName',
    label: '工作班成员',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'happenDate',
    label: '工作时间',
    component: 'RangePicker',
    componentProps: {
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
    },
    colProps: { span: 8 },
  },
];

export const systemColumns: BasicColumn[] = [
  {
    title: 'id',
    dataIndex: 'id',
    ifShow: false,
    width: 90,
  },
  {
    title: '派工单编号',
    dataIndex: 'pdbh',
    width: 150,
  },
  {
    title: '工作类型',
    dataIndex: 'gzlx',
    width: 150,
  },
  {
    title: '工作任务',
    dataIndex: 'rationName',
    width: 150,
  },
  {
    title: '工作负责人',
    dataIndex: 'psnName',
    width: 150,
  },
  {
    title: '工作班成员',
    dataIndex: 'psnName',
    width: 150,
  },
  {
    title: '工作票类型',
    dataIndex: 'psnName',
    width: 150,
  },
  {
    title: '计划开始时间',
    dataIndex: 'beginDate',
    width: 150,
  },
  {
    title: '计划结束时间',
    dataIndex: 'endDate',
    width: 150,
  },
];
